export const initState = {
    userInfo:  sessionStorage.getItem("info")?JSON.parse(sessionStorage.getItem("info")):{},
}

export const reducer = (state,action) =>{
    switch (action.typle){
        case "changeuserInfo":
        return{
            ...state,
            userInfo:action.userInfo
        }
        default:
            return state
    }
}

export const actions = {
    cahngeuserInfo: userInfo =>{
        if(userInfo.token){
            sessionStorage.setItem("info",JSON.stringify(userInfo))
        }else{
            sessionStorage.removeItem("info")
        }
        return {type:"changeuserinfo",userInfo}
    }
}